package Queue;

public class MyQueue {

	private Node head;
	private Node tail;
	private int size;

	public MyQueue() {
		head = null;
		tail=null;
		
		size = 0;
	}

	public void enqueue(int elem) {
		Node node = new Node(elem, null);

		if (size == 0) {
			head=node;
			tail=node;
			
		
		} else {
			tail.setNext(node);
			tail = node;
		}
		size++;
	}

	public int dequeue() throws Exception {
		
			if (size == 0) {
				throw new Exception("Queue is empty.");
			}
			
			int tmp = head.getElement();
			head = head.getNext();
			size--;
			
			return tmp;
		
	}

	public boolean isEmpty() {
		return size == 0;
	}

	public int size() {
		return size;
	}
	
	}
